﻿@using System.Diagnostics

@{
    ViewData["Title"] = "首页";
    var lang = System.Globalization.CultureInfo.CurrentCulture.DisplayName;
    var assembly = System.Reflection.Assembly.GetEntryAssembly();
    var version = string.Empty;
    var fileVersion = string.Empty;
    if (assembly is not null)
    {
        var versionInfo = FileVersionInfo.GetVersionInfo(assembly.Location);
        version += "v" + versionInfo.ProductVersion;
        fileVersion = "v" + versionInfo.FileVersion;
    }
}

<div class="welcome-page">
    <h1>
        <img src="~/icons/identity.png">
        这里是统一授权和认证中心
        <small class="text-muted">(语言: @lang, 文件版本: @fileVersion, 产品版本: @version)</small>
    </h1>

    <div class="form-content" data-toggle="form" data-field="administrator">
        <div class="form-heading">
            <span>管理员特有功能</span>
        </div>
        <div class="form-body">
            <div class="row">
                <span data-field="ipAddresses" id="ipAddresses" data-title="现有IP地址白名单" data-size="12,1,10" data-loaded="#:getIpAddresses"></span>
            </div>
            <div class="row">
                <input data-field="ipAddress" id="ipAddress" data-title="IP地址" required data-size="3,4,8" />
                <button data-button="get" data-icon="fa fa-check" data-url="/api/Initial/AllowIpAddress" data-before-submit="#:addIpAddress">添加IP地址</button>
                <button data-button="get" data-icon="fa fa-check" data-url="/api/Initial/RemoveCache/CACHE_APP_AllowedIpAddresses" data-validation-in-sbumit="false">刷新IP地址缓存</button>
            </div>
            <div class="row">
                <input data-field="attachments" data-size="12,1,10" data-title="上传文件" data-label="上传特殊文件" data-with-attachments="true" data-role="kendoUpload" type="file" data-file-count="1" data-file-size="1024000" />
            </div>
        </div>
    </div>
</div>

<script>
    function addIpAddress(el) {
        var ipAddress = $('#ipAddress').val();
        if($.com.hasValue(ipAddress)) {
            el.options.url += "?ipAddress="+ipAddress;
        }
    }

    function getIpAddresses() {
        $.api.get(`/api/parameters?$filter=key eq 'AllowedIpAddresses'&$select=id,value`, data => {
            $('#ipAddresses').html(data.data[0].value).change();
        });
    }
</script>